@extends("/main_template",menu="opedncard")
@import com.zj.bean.*;
@import java.util.List;
@args List<Command> commandList;
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>活动助手</title>
    <link rel="stylesheet" href="@res("/static/css/bootstrap.min.css")">
    <link rel="stylesheet" href="@res("/static/css/main.css")">
</head>
<body class="manage">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <i class="glyphicon glyphicon-bookmark pull-left"></i>
            <h3 class="panel-title">口令表管理</h3>
        </div>
        <div class="panel-body row table_content">
            <form action="?" class="form-inline row" method="get">
                <div class="form-group col-xs-4" style="text-align: center;">
                    <label for="txtCardId" class="control-label">客户</label>
                    <input name="cusName" value="@val('cusName')" type="text" class="form-control" id="txtCardId" placeholder="客户"/>
                    <button type="submit" class="btn btn-success">查询</button>
	                <input type="button"  id="addCmd" class="btn btn-success"   value="新增"/>
                </div>
            </form>
                <div style="padding: 50px 10px;width: 92%;margin: 0px auto;">
                    <table id="table_data" class="table table-hover">
                        <thead>
                        <tr>
                            <th>库ID</th>
                            <th>库名称</th>
                            <th>客户名称</th>
                            <th>刷新间隔</th>
                            <th>剩余/总数</th>
                            <th>状态</th>
                            <th>增加口令</th>
                            <th>导出剩余口令</th>
                        </tr>
                        </thead>
                        <tbody>
                        	@if(commandList != null){
                        		@for(Command cm : commandList){
		                        <tr>
		                            <td>@cm.getId()</td>
		                            <td>@cm.getCmdName()</td>
		                            <td>@cm.getCusName()</td>
		                            <td>@cm.getRefreshTime()</td>
		                            <td>@cm.getLeftNum()/@cm.getTotalNum()</td>
		                            <td>@if(cm.getStatus() == 1){
		                            		开启
		                            	}else{
		                            		暂停
		                            	}
		                            </td>
		                            <td><a href="#" onclick="imports('@cm.getId()','@cm.getCmdName()')">导入</a></td>
		                            <td>导出</td>
		                        </tr>
		                        }
	                        }
                        </tbody>
                    </table>
                </div>
        </div>
    </div>
<div id="jsAuthor" class="hidden">
    <div class="row">
        <h2 class="col-xs-12 text-danger text-center"><span id="edit"></span>口令库</h2>
        <form class="form-horizontal col-xs-9" id="powerCard">
            <input type="hidden" id="id" name="id" value="-1"/>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">口令库名称</label>
                <div class="col-xs-8">
                    <input type="text" name="cmdName" class="form-control" id="cmdName" placeholder="请输入口令库名称">
                </div>
            </div>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">客户名称</label>
                <div class="col-xs-8">
                    <input type="text" name="cusName" class="form-control" id="cusName" placeholder="请输入客户名称">
                </div>
            </div>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">更新间隔(分钟)</label>
                <div class="col-xs-8">
                    <input type="text" name="refreshTime" class="form-control" id="refreshTime" placeholder="分钟">
                </div>
            </div>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">状态</label>
                <div class="col-xs-8">
                    <select name="statuss" id="status" class="form-control">
	                        <option value="0">暂停</option>
	                        <option value="1">开启</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
</div>


<div id="jsAuthor2" class="hidden">
    <div class="row">
        <h2 class="col-xs-12 text-danger text-center">导入口令到口令库</h2>
        <form class="form-horizontal col-xs-9" id="cmds">
            <input type="hidden" id="cmdId" name="cmdId" value="-1"/>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">口令库名称</label>
                <div class="col-xs-4">
                    <span id="cm"></span>
                </div>
            </div>
            <div class="form-group">
                <label for="pwdAuthor" class="col-xs-4 control-label">口令</label>
                <div class="col-xs-8">
                    <input type="text" name="cmdStr" class="form-control" id="cmdStr" placeholder="请输入口令">
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="@res("/static/js/jquery-1.10.2.min.js")"></script>
<script type="text/javascript" src="@res("/static/js/bootstrap.min.js")"></script>
<script type="text/javascript" src="@res("/static/js/main.js")"></script>
<script>
	var appRoot="@url("/")";
	$("#table_data tr").dblclick(function(){
		  var cmId = $(this).children('td').eq(0).text();
		  var cmName = $(this).children('td').eq(1).text();
		  var csName = $(this).children('td').eq(2).text();
		  var refreshTime = $(this).children('td').eq(3).text();
		  var status = $(this).children('td').eq(5).text();
		  if(status.trim() == '开启')status = 1;
		  else status = 0;
		  $("#id").val(cmId);
		  $("#cmdName").val(cmName);
		  $("#cusName").val(csName);
		  $("#refreshTime").val(refreshTime);
		  $("#status").val(status);
		  $("#edit").text("修改");
		  util.el.confirm("#jsAuthor",function () {
			 util.request.post("/act/command.json",{id:cmId,cmdName:$("#cmdName").val(),cusName:$("#cusName").val(),refreshTime:$("#refreshTime").val(),status:$("#status").val()},function(data){
				 $("#jsBtnDrawMoney").removeAttr("disabled");
				 util.el.alert("修改成功!");
				 window.location.reload();
			});
	  	 });
		  
	});
	$("#addCmd").click(function () {
	   	$("#edit").text("新增");
		  $("#cmdName").val("");
		  $("#cusName").val("");
		  $("#refreshTime").val("");
	    util.el.confirm("#jsAuthor",function () {
	    	util.request.post("/act/command.json",{id:-1,cmdName:$("#cmdName").val(),cusName:$("#cusName").val(),refreshTime:$("#refreshTime").val(),status:$("#refreshTime").val()},function(data){
				 $("#jsBtnDrawMoney").removeAttr("disabled");
				 util.el.alert("添加成功!");
				 window.location.reload();
			});
	   });
   });
	function imports(cmdId,cmdName){
		$("#cmdId").val(cmdId);
		$("#cm").text(cmdName);
		util.el.confirm("#jsAuthor2",function () {
	    	util.request.post("/act/addCmd.json",util.el.data("#cmds"),function(data){
				 $("#jsBtnDrawMoney").removeAttr("disabled");
				 util.el.alert("导入成功!");
				 window.location.reload();
			});
	   });
	}
</script>
</body>
</html>